#!/bin/bash

MYSELF="deepseek-example-0.deepseek-example.default.svc"

while true; do 
  IP=$(getent hosts $MYSELF|awk '{print $1}')

  [ -n "$IP" ] || { echo "[init_0.sh]dnslookup $MYSELF" >&2; sleep 2; continue; }

  break

done


export VLLM_HOST_IP=$IP

#export GLOO_SOCKET_IFNAME=eth0

#export TP_SOCKET_IFNAME=eth0

echo "[init_0.sh]$VLLM_HOST_IP $MYSELF" >&2

ray start --block --head --port=6379 &

while true;do 
  sleep 5
  [ $(ray status 2>&1|grep -E "(no pending nodes)|(no failures)"|wc -l) -eq 2 ] && break
  echo "[init_0.sh]waiting for ray cluster to be ready..." >&2
done

ray status >&2

vllm serve \
  /root/.cache/huggingface/DeepSeek-R1-Distill-Qwen-1.5B/ \
  --trust-remote-code \
  --tensor-parallel-size 2 \
  --pipeline-parallel-size 2 \
  --max-model-len 4096  \
  --gpu-memory-utilization 0.9 \
  --served-model-name DeepSeek-R1 \
  --port 8080 \
  --host 0.0.0.0

